home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / isdn / isdn-setup.frm.z / isdn-setup.frm
Encoding:
Text File  |  1997-07-30  |  8.5 KB  |  301 lines

  1. #!/usr/bin/perl5
  2. #
  3. # isdn.cgi 
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: isdn-setup.frm,v 1.40 1997/07/15 20:10:18 shotes Exp $
  21.  
  22. # currently allowed only one switch type (and pair of SPID #'s),
  23. # but can have multiple connection names (and phone numbers).
  24. # this is to remove ambiguity that entries in isdnd.options know
  25. # nothing of connection names.  code will comment out conflicting
  26. # entries.
  27.  
  28. require "/usr/OnRamp/lib/OnRamp.pm";
  29. require "/usr/OnRamp/lib/java.pm";
  30.  
  31. $confS = "/etc/uucp/Systems";
  32. $conf = "/etc/config/isdnd.options";
  33. $dummy = "/etc/config/isdnd.options.tmp";
  34. $pwdfile = "/etc/passwd";
  35. $myname = "isdn-setup.cgi";
  36. $title = "ISDN Setup";
  37.  
  38. if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
  39. else { $br_index = 0; }
  40.  
  41. $js =
  42. "br_index = $br_index;
  43. $js_standard
  44. $js_error_box
  45. $js_phone
  46. $js_hostname
  47. function checkForm(form) {
  48.     if (form.isdns[br_index].checked) {
  49.         if (!testHostname(form.nme, form.nme.value, \"connection name\", 0)) return (false);
  50.         if (!testPhone(form.phone)) return (false);
  51.         if (!testSwitch(form)) return (false);
  52.     } return (true);
  53. }
  54. function testSwitch(form) {
  55.     Ctrl = form.switchtype; selnum = Ctrl.selectedIndex;
  56.     word1 = form.spid1.value; word2 = form.spid2.value;
  57.     selected = Ctrl.options[selnum].text;
  58.     if (selected == \"DMS100\" || selected == \"NI1\") {
  59.         if(word1 == \"\" || word2 == \"\") { 
  60.             errorBox (Ctrl, \"Two SPID numbers required for \\nswitch type \" + selected); 
  61.             return (false); 
  62.         }
  63.         for(i=0; i < word1.length; i++) { 
  64.             if (! checkInt_c(word1.charAt(i), 10)) {
  65.                 errorBox (Ctrl, \"Invalid SPID number: \" + word1); 
  66.                 return (false); 
  67.             } 
  68.         }
  69.         for(i=0; i < word2.length; i++) { 
  70.             if (! checkInt_c(word2.charAt(i), 10)) {
  71.                 errorBox (Ctrl, \"Invalid SPID number: \" + word2); 
  72.                 return (false); 
  73.             } 
  74.         }
  75.     } return (true);
  76. }";
  77.  
  78.  
  79. print "Content-type: text/html\n\n";
  80.  
  81. @types = ('DMS100','NI1','5ESS','NTT','NET3/DSS1','1TR6','VN3','TPH');
  82.  
  83. &get_fields;
  84.  
  85. &getInfo;
  86.  
  87. $help = $document_root . $ENV{"SCRIPT_NAME"};
  88. $help =~ s/cgi$/hlp/;
  89. exec $help if ($fld{'help'} eq "Help");
  90.  
  91. if ($fld{"doit"} eq "Ok") {
  92.     if ($fld{'isdns'} eq "Yes") { &formValidation; };
  93.     &edit; 
  94.     &getInfo; 
  95.     &putValues;
  96.     if (!$message) { $message = "No change."; }
  97. } else { &putValues; }
  98.  
  99. if (-e "/usr/etc/isdnd") { &generic; }
  100. else {
  101.     &title_block($title);
  102.     &header_block($title);
  103.     print "<i>ISDN software not installed.  Install subsystem </i><b>isdn_eoe.sw</b><i>
  104.     from the distribution CD (6.2 or 6.3), or for OS 6.4 please install
  105.     the appropriate patch.</i>";
  106. }
  107.  
  108. sub formValidation {
  109.     &error("Invalid telephone number entry.") if &check_phone($fld{'phone'});
  110.     &error("Invalid connection name.") if $fld{'nme'} =~ /$METACHARS/o;
  111.     
  112.     if ($fld{'switchtype'} eq 'DMS100' || $fld{'switchtype'} eq 'NI1') {
  113.     &error("Invalid SPID number: $fld{'spid1'}.") 
  114.         if ($fld{'spid1'} =~ /[^0-9]/);
  115.     &error("Invalid SPID number: $fld{'spid2'}.") 
  116.         if ($fld{'spid2'} =~ /[^0-9]/);
  117.     if (!$fld{'spid1'}) 
  118.         { &error("Two SPID numbers required for this switch."); }
  119.     if (!$fld{'spid2'}) 
  120.         { &error("Two SPID numbers required for this switch."); }
  121.     }
  122. }
  123.  
  124. sub error {
  125.     &error_block($_[0]);
  126.     %val = %fld;
  127.     &generic;
  128.     exit 0;
  129. }
  130.  
  131. sub edit {
  132.     if ($fld{'isdns'} ne $isdns) { &editStatus; }
  133.     if ($fld{'isdns'} eq "Yes") { &writeFile; }
  134. }
  135.  
  136. sub writeFile {
  137.     if (&checkOpChange) {
  138.     open(IN,"< $conf");
  139.     open(OUT,"> $dummy");
  140.     while(<IN>) {
  141.         $line = $_;
  142.         if (substr($_,0,2) ne "-t") { print OUT $_; }
  143.         else { print OUT "# $line"; }
  144.     }
  145.     if ($fld{'switchtype'} eq "NET3/DSS1") {
  146.         print OUT "-t NET3";
  147.     } else {
  148.         print OUT "-t $fld{'switchtype'}";
  149.     }
  150.     if ($fld{'switchtype'} eq 'DMS100' || $fld{'switchtype'} eq 'NI1') {
  151.         print OUT " -s $fld{'spid1'} -s $fld{'spid2'}";
  152.     }
  153.     print OUT "\n";
  154.     close(OUT);
  155.     close(IN);
  156.     rename($dummy,$conf);
  157.     }
  158.  
  159.     $fld{'phone'} =~ s/-//g;
  160.     if (&checkSyChange) {
  161.     open(IN,"< $confS");
  162.     open(OUT,"> $dummy");
  163.     while(<IN>) {
  164.         @items = split(/\s+/);
  165.         if (substr($items[0],0,1) eq '#') { print OUT $_; next; }
  166.         if ($items[0] ne $nme || $items[2] ne 'ISDN') { print OUT $_; }
  167.         else { print OUT "# $_"; }
  168.     }
  169.     if ($fld{'switchtype'} eq "NET3/DSS1") {
  170.         print OUT 
  171.         qq|$fld{'nme'} Any ISDN 38400 "" "" ISDNCALL[64]$fld{'phone'} CONNECTED\n|;
  172.     } else {
  173.         print OUT 
  174.         qq|$fld{'nme'} Any ISDN 38400 "" "" ISDNCALL[56]$fld{'phone'} CONNECTED\n|;
  175.     }
  176.     close(OUT);
  177.     close(IN);
  178.     chmod 0600, $confS;
  179.     rename($dummy,$confS);
  180.     chmod 0400, $confS;
  181.     }
  182.     $message .= "Parameters edited.";
  183. }
  184.  
  185. sub checkSyChange {
  186.     if ($fld{'nme'} ne $nme || $fld{'phone'} ne $phone) { return 1; }
  187.     return 0;
  188. }
  189.  
  190. sub checkOpChange {
  191.     if ($fld{'switchtype'} ne $swType) { return 1; }
  192.     if ($swNum > 1) { return 0; }
  193.     if ($fld{'spid1'} ne $spid[0]) { return 1; }
  194.     if ($fld{'spid2'} ne $spid[1]) { return 1; }
  195.     return 0;
  196. }
  197.  
  198. sub editStatus {
  199.     if ($fld{'isdns'} eq "Yes") { 
  200.     system("/etc/chkconfig", "isdnd", "on");
  201.         `/bin/csh -c '(/bin/csh /etc/init.d/isdnd stop) >&! /dev/null'`;
  202.         `/bin/csh -c '(/bin/csh /etc/init.d/isdnd start) >&! /dev/null'`;
  203.         $message = "ISDN enabled.  ";
  204.     }
  205.     else {
  206.     system("/etc/chkconfig", "isdnd", "off");
  207.         `/bin/csh -c '(/bin/csh /etc/init.d/isdnd stop) >&! /dev/null'`;
  208.         $message = "ISDN disabled.  ";
  209.     }
  210. }
  211.  
  212. sub putValues {
  213.     $val{'isdns'} = $isdns;
  214.     $val{'nme'} = $nme;
  215.     $val{'phone'} = $phone;
  216.     $val{'switchtype'} = $swType;
  217.     $val{'spid1'} = $spid[0];
  218.     $val{'spid2'} = $spid[1];
  219. }
  220.    
  221. sub generic {
  222.     &js_title_block($title,$js);
  223.     &header_block($title);
  224.  
  225.     print "<i>$message</i>";
  226.  
  227.     print "<form name=\"StandardForm\" action=$myname method=post onSubmit=\"return runSubmit()\">\n";
  228.  
  229.     print "<center><table cellpadding=5 width=450>\n";
  230.  
  231.     print "<tr><th align=left>Enable ISDN:</th><th align=left>";
  232.     print &radio('isdns',$val{'isdns'},"Yes","No");
  233.     print "</th></tr>";
  234.  
  235.     print "<tr><th align=left>Connection name for host answering calls:
  236.         </th><th align=left>";
  237.     print &text('nme',$val{'nme'},20);
  238.     print "</th></tr>";
  239.     
  240.     print "<tr><th align=left>Phone number for host answering calls:
  241.         </th><th align=left>";
  242.     print &text('phone',$val{'phone'},20);
  243.     print "</th></tr>";    
  244.  
  245.     print "<tr><th align=left>Type of switch used for connections:
  246.         </th><th align=left>";
  247.     print &select('switchtype',$val{'switchtype'},'DMS100','NI1','5ESS',
  248.         'NTT','NET3/DSS1','1TR6','VN3','TPH');
  249.     print "</th></tr>\n";
  250.  
  251.     print "<tr><th align=left>SPID #1:</th><th align=left>";
  252.     print &text('spid1',$val{'spid1'},20);
  253.     print "</th></tr>\n";
  254.  
  255.     print "<tr><th align=left>SPID #2:</th><th align=left>";
  256.     print &text('spid2',$val{'spid2'},20);
  257.     print "</th></tr></table></center><br>\n";
  258.  
  259.     print "<i>Note: SPID numbers are required only for switch types\n";
  260.     print "DMS100 and NI1.</i><br><br>\n";
  261.  
  262.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
  263.  
  264.     print '</form>';
  265. }
  266.  
  267. sub getInfo {
  268.     $isdns = &get_config("isdnd");
  269.     $spid[0] = $spid[1] = "";
  270.  
  271.     open(IN,"< $conf");
  272.     while(<IN>) {
  273.     $line = $_;
  274.     if (substr($line,0,2) eq "-t") {
  275.         @args = split(/\s+/,$line);
  276.         $swType = $args[1];
  277.         if ($swType eq "NET3") { $swType = "NET3/DSS1"; }
  278.         $countSPID = 0;
  279.         for ($i=0;$i<=$#args;$i++) {
  280.         if ($args[$i] eq "-s") { 
  281.             $spid[$countSPID] = $args[$i+1];
  282.             $countSPID++; 
  283.         }
  284.         }
  285.     }
  286.     }
  287.     close(IN);
  288.  
  289.     open(IN,"< $confS");
  290.     while(<IN>) {
  291.     @items = split(/\s+/);
  292.     if (substr($items[0],0,1) eq '#') { next; }
  293.     if ($items[2] eq 'ISDN') { 
  294.         $nme = $items[0];
  295.         $items[6] =~ /.*\](\w+)$/;
  296.         $phone = $1;
  297.     }
  298.     }
  299.     close(IN);
  300. }
  301.